package service

import (
	"net/http"

	"gitee.com/zenpk/backend-demo/internal/dal"
	"gitee.com/zenpk/backend-demo/internal/dto"
	"gitee.com/zenpk/backend-demo/internal/middleware"
	"github.com/gin-gonic/gin"
)

type GradeAlter struct{}

var gradeAlterDal dal.GradeAlter

func (s *GradeAlter) GetGradeAlter(c *gin.Context) {
	var gradeAlter dal.GradeAlter
	var req dto.GetGradeAlterReq
	//请求绑定json
	if err := c.ShouldBindJSON(&req); err != nil {
		middleware.Logger.Warn(err.Error())
		c.JSON(http.StatusOK, dto.GetGradeAlterResp{
			SuccessCode: 0,
			Msg:         err.Error(),
		})
		return
	}
	gradeAlter, err := gradeAlterDal.GetGradeAlter(req.StudentNum)

	if err != nil {
		middleware.Logger.Warn(err.Error())
		c.JSON(http.StatusOK, dto.GetGradeAlterResp{
			SuccessCode: 0,
			Msg:         err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, dto.GetGradeAlterResp{
		SuccessCode: 1,
		Msg:         "获取成功",
		StudentNum:  req.StudentNum,
		GradeAlter:  gradeAlter,
	})
}
